package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;

import com.woniu.pojo.Mark;
import com.woniu.service.IMarkService;
import com.woniu.vo.MarkQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 收藏表 前端控制器
 * </p>
 *
 * @author 刘岩
 * @since 2022-10-11
 */
@RestController
@RequestMapping("/mark")
@Api(tags = "收藏管理")
public class MarkController extends BaseController{
    
    @Autowired
    private IMarkService markService;

    @ApiOperation("根据ID查询收藏")
    @GetMapping("/id/{id}")
    public Result queryMarkById(@PathVariable Long id){
        Mark mark = markService.getById(id);
        return toDataResult(mark);
    }

    @ApiOperation("根据用户ID查询所有收藏")
    @GetMapping("/userId/{userId}")
    public Result queryMarkByUserId(@PathVariable Long userId){
        List<Mark> MarkList = markService.queryMarkByUserId(userId);
        return toDataResult(MarkList);
    }

    /*@ApiOperation("查询所有")
    @GetMapping("queryAll")
    public Result queryAll(){
        List<Mark> MarkList = markService.list();
        return toDataResult(MarkList);
    }

    @ApiOperation("分页模糊搜索收藏")
    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result search(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody MarkQueryVo markQueryVo){
        PageResult pageResult = markService.search(currentPage, pageSize, markQueryVo);
        return toDataResult(pageResult);
    }*/

    /*@ApiOperation("根据名字查询收藏")
    @GetMapping("/title/{title}")
    public Result queryByTitle(@PathVariable String title){
        List<Mark> MarkList = markService.queryByTitle(title);
        return toDataResult(MarkList);
    }*/

    @ApiOperation("增加收藏跟新相应收藏数量")
    @PostMapping
    public Result add(@RequestBody Mark mark){
        int row = markService.saveMark(mark);
        return toDataResult(row);
    }

    @ApiOperation("编辑收藏")
    @PutMapping
    public Result edit(@RequestBody Mark Mark) {
        boolean flag = markService.updateById(Mark);
        return toResult(flag);
    }

    @ApiOperation("根据ID删除收藏")
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Long id) {
        boolean flag = markService.removeById(id);
        return toResult(flag);
    }


    @ApiOperation("批量删除收藏")
    @PostMapping("/batch")
    public Result removeBatch(@RequestBody List<Long> ids) {
        boolean flag = markService.removeBatchByIds(ids);
        return toResult(flag);
    }



}